package com.ys.controller.web.hr;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.bo.vo.W;
import com.ys.config.MenuId;
import com.ys.entity.base.TbMaterial;
import com.ys.service.sys.CommonApiService;

@Controller
@RequestMapping("/web/hr/tbMaterial")
public class WebTbMaterialController {
	
	@Autowired
	private CommonApiService<TbMaterial> commonApiService;
	
	/*
	 * 新增
	 */
	@RequiresPermissions("tbMaterial:add")
	@GetMapping("/toAdd")
	public String toAdd(Model model, HttpServletRequest request, HttpServletResponse response){
		try {
			TbMaterial entity = new TbMaterial();
			entity.setCode(commonApiService.getCommonNextUkey(MenuId.TB_Material, "Code"))
				.setStatus(1);
			return commonApiService.toAdd(model, entity, MenuId.TB_Material, null, null);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, e.getMessage());
		}
	}
	
	/*
	 * 修改
	 */
	@RequiresPermissions("tbMaterial:edit")
	@GetMapping("/toEdit")
	public String toEdit(Model model, HttpServletRequest request, HttpServletResponse response,
			Long id){

		try {
			return commonApiService.toEdit(model, id, new TbMaterial(), MenuId.TB_Material, null, null);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, e.getMessage());
		}
	}
}
